//
//  KLCurrencyEntity.m
//  KLCurrency
//
//  Created by apple on 2017/12/2.
//  Copyright © 2017年 bonc. All rights reserved.
//

#import "KLCurrencyEntity.h"

@implementation KLCurrencyEntity

-(instancetype)initWithDictionary:(NSDictionary *)dict {
    
    KLCurrencyEntity *currencyEntity = [[[self class] alloc] init];
    
    currencyEntity.name = [dict objectForKey:@"name"];
    currencyEntity.nation = [dict objectForKey:@"nation"];
    currencyEntity.abbreviation = [dict objectForKey:@"abbreviation"];
    currencyEntity.symbol = [dict objectForKey:@"symbol"];
    
    currencyEntity.main = [[dict objectForKey:@"main"] boolValue];
    currencyEntity.common = [[dict objectForKey:@"common"] boolValue];
    currencyEntity.local = [[dict objectForKey:@"local"] boolValue];
    
    return currencyEntity;
}

- (instancetype)initWithFMResultSet:(FMResultSet *)resultSet {
    KLCurrencyEntity *currencyEntity = [[[self class] alloc] init];
    
    currencyEntity.id = [resultSet longLongIntForColumn:@"id"];
    currencyEntity.name = [resultSet stringForColumn:@"name"];
    currencyEntity.nation = [resultSet stringForColumn:@"nation"];
    currencyEntity.abbreviation = [resultSet stringForColumn:@"abbreviation"];
    currencyEntity.symbol = [resultSet stringForColumn:@"symbol"];
    
    currencyEntity.main = [resultSet boolForColumn:@"main"];
    currencyEntity.common = [resultSet boolForColumn:@"common"];
    currencyEntity.local = [resultSet boolForColumn:@"local"];

    return currencyEntity;
}

- (id)copyWithZone:(NSZone *)zone {
    
    KLCurrencyEntity *currencyEntity = [[[self class] allocWithZone:zone] init];
    currencyEntity.id = self.id;
    currencyEntity.name = [self.name copy];
    currencyEntity.nation = [self.nation copy];
    currencyEntity.abbreviation = [self.abbreviation copy];
    currencyEntity.symbol = [self.symbol copy];
    
    currencyEntity.main = self.main;
    currencyEntity.common = self.common;
    currencyEntity.local = self.local;
    
    return currencyEntity;
}


@end
